package com.ytjj.qmyx.data.amqp.consumer;

import com.alibaba.fastjson.JSONObject;
import com.ytjj.common.utils.DateTimeUtil;
import com.ytjj.common.utils.HttpClientUtil;
import com.ytjj.qmyx.data.service.impl.MsgServiceImpl;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;

/**
 *
 * 
 * @describe 测试
 */
@Slf4j
public class TestShort {


    public static void main2(String[] args) {

//        BigDecimal bd = new BigDecimal(String.valueOf(99.99));
//        BigDecimal bigDecimal = bd.setScale(1, RoundingMode.DOWN);
//        System.out.printf("----->"+bigDecimal.toString());
        getShortUrl(null);

    }

    /**
     * 生成订单页面
     */
    public static void main(String[] args) {
        String orderListUrl = "https://svip.XXXX.com/pages/order/orderlist.html";
        MsgServiceImpl msgService = new MsgServiceImpl();
        //短信长链
        String smsUrl_long = msgService.generateLongUrl(orderListUrl, "15941000372", "h5",null,null);
        System.out.println("-------------->"+smsUrl_long);
    }

    public static String getShortUrl(String longUrl){
        long curTimeMillis = System.currentTimeMillis();
        System.out.println("====短链接口开始====" + curTimeMillis);
        System.out.println("====短链接口开始====" + curTimeMillis);
        Map<String, String> map = new HashMap<String, String>();
        map.put("url", "www.baidu.com");
        map.put("format", "json");
        map.put("key", "63babb6a27cfc7575263ca7e9585f@655536a189180be15daabcd90ae5b891");
        map.put("expireDate", DateTimeUtil.addtime(DateTimeUtil.DateToStr(new Date()),30));
        map.put("domain", "15");
        log.info("====短链接口开始参数:{}====", JSONObject.toJSONString(map));
        String result = HttpClientUtil.doGet("http://api.3wt.cn/api.htm", map);
        log.info("====短链接口结束返回:{}====",result);
        Map resultMap = JSONObject.parseObject(result, Map.class);
        String code = String.valueOf(resultMap.getOrDefault("code", ""));
        String err = String.valueOf(resultMap.getOrDefault("err", ""));
        String url = String.valueOf(resultMap.getOrDefault("url", ""));
        url = url.replace("http://", "");
        url = url.replace("https://", "");
        if (!"0".equals(code)) {
            log.info("====批量生成短链失败===code:{},msg:{}", code, err);
        }
        System.out.printf("返回====》"+url);
        return url;
    }
}
